package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.MinIOConfig;
import com.itheima.utils.MinIOUtils;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/upload")
public class FileController {


    @Resource
    private MinIOConfig minIOConfig;
    @PostMapping
    public Result upload(@RequestParam("file") MultipartFile file) throws Exception {
        String filename = file.getOriginalFilename();
        filename = "face"+
                "_"+
                filename;
        MinIOUtils.uploadFile(minIOConfig.getBucketName(),
                filename,
                file.getInputStream());
        String faceUrl = minIOConfig.getFileHost() + "/" + minIOConfig.getBucketName()+ "/"+ filename;
        System.out.println(faceUrl);
        return Result.success(faceUrl);
    }
}